#!/bin/bash
#description: init debian system

set -e


command_exists() {
	command -v "$@" >/dev/null 2>&1
}


#if [[ $UID != 0 ]]
#then 
#    echo "Fatal! Please run as root!" 
#    exit 1
#fi
#
#b=$(expr substr "$(cat /etc/issue)" 1 12)
#if [ "$b" = "Ubuntu 20.04" ]
#then echo "">/dev/null
#else 
#    echo "请使用Ubuntu 20.04运行此脚本"
#    exit 1
#fi
#
#echo "脚本开始运行..."
#echo "正在安装阿里云镜像..."
#
#if [ -d /etc/apt/sources.list ]
#then 
#    mv /etc/apt/sources.list /etc/apt/sources.list.bak
#fi
#
#sudo echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
#
#deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
#
#deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
#
#deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
#
#deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
#">/etc/apt/sources.list
#
#echo "正在更新安装源..."
#sudo apt-get update>/dev/null
#echo "OK"
#echo "正在更新软件..."
#sudo apt-get upgrade -y>/dev/null
#echo "OK"
#
#echo "正在安装配置Neovim"
#
#command_exists nvim||{
#	echo "正在安装Neovim"
#	sudo apt-get install neovim -y>/dev/null
#}
 echo "设置npm安装源为淘宝源"
 npm config set registry https://registry.npm.taobao.org
echo "配置Neovim" 
nvim -c :PlugInstall -c :qa
cp -r ~/.local/share/nvim/site/plugged/gruvbox/colors ~/.local/share/nvim/site/
echo "安装已全部完成"

ommand_exists zsh||{
   echo "正在安装ZSH..."
   sudo apt-get install zsh -y>/dev/null
}
echo "将zsh设置为默认Shell"
sudo chsh -s /bin/zsh $USER

command_exists git||{
	echo "正在安装git..."
	sudo apt-get install git -y>/dev/null
}
git config --global user.name "zimingzpp"
git config --global user.email "zimingzpp@qq.com"

echo "正在安装Ohmyzsh安装脚本"
#sh -c "$(wget -O- https://gitee.com/zimingzpp/ohmyzsh/raw/master/tools/install.sh>dev/null)"
if [ -d ~/.oh-my-zsh ]
then 
    rm -rf ~/.oh-my-zsh
    rm -rf ~/.zsh*
fi
wget  https://gitee.com/zimingzpp/ohmyzsh/raw/master/tools/install.sh
sed -i '286s/exec/#exec/g' ./install.sh
sed -i '172s/read\ opt/opt=y/g' ./install.sh
sh ./install.sh
rm ./install.sh*
echo "安装语法高亮插件"
git clone https://gitee.com/zimingzpp/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting>/dev/null
chmod -R 755 ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
echo "安装自动补全插件"
git clone https://gitee.com/zimingzpp/zsh-autosuggestions.git ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions>/dev/null
chmod -R 755 ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
sed -i '71s/git/git\ zsh-autosuggestions\ zsh-syntax-highlighting/g' ~/.zshrc
echo "安装已全部完成"
exec  zsh -l

